package com.quanshu.exchange.support.utils;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by jye on 2017/8/24.
 */

public class CheckUtil {

    // 手机号码的正则表达式11位手机号码)（中国）
    private static final String telNumRule = "^1[345789]\\d{9}$";

    // 密码的正则表达式(要求同时有数字和字母，长度最小6，最大20)
//    private static final String passRule = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";

    // 用户名正则表达式
//    private static final String userNameRule = "^[a-zA-z][a-zA-Z0-9_]{6,20}$";
    private static final String userNameRule = "^[a-zA-z][a-zA-Z0-9_]{7,16}$";
    private static final String passRule = "^[a-zA-z][a-zA-Z0-9]{6,16}$";

    public static boolean isValidate(String content) {
        if (content != null && !"".equals(content.trim())) {
            return true;
        }
        return false;
    }

    public static boolean isValidate(String... contents) {
        for (int i = 0; i < contents.length; i++) {
            if (contents[i] == null || "".equals(contents[i].trim())) {
                return false;
            }
        }
        return true;
    }

    public static boolean isValidate(List list) {
        if (list != null && !list.isEmpty()) {
            return true;
        }
        return false;
    }

    public static boolean isValidate(Map map) {
        if (map != null && !map.isEmpty()) {
            return true;
        }
        return false;
    }

    /**
     * @return
     */
    public static boolean checkTelNumRule(String str) {
        if (str == null || str.length() <= 0) {
            return false;
        }
        Pattern pat = Pattern.compile(telNumRule);
        Matcher mat = pat.matcher(str);

        return mat.find();
    }

    /**
     * 密码的正则表达式(要求同时有数字和字母，长度最小6，最大20)
     *
     * @param str
     * @return
     */
    public static boolean checkPwdRule(String str) {
        if (str == null || str.length() <= 0) {
            return false;
        }
        Pattern pat = Pattern.compile(passRule);
        Matcher mat = pat.matcher(str);

        return mat.find();
    }

    /**
     * @return
     */
    public static boolean checkUserNameRule(String str) {
        if (str == null || str.length() <= 0) {
            return false;
        }
        Pattern pat = Pattern.compile(userNameRule);
        Matcher mat = pat.matcher(str);

        return mat.find();
    }

}
